﻿@using hc.epm.DataModel.Business;
@using hc.epm.Common;
@using hc.Plat.Common.Extend;
@using hc.epm.ViewModel;
@model ChangeView
@{
    ViewBag.Title = "查看变更";
}

<body>
@if (Model == null)
{
    <div class="contentData">
        <div class="tab">
            该数据已删除或者不存在！
        </div>
    </div>
}
else {
    <div class="contentData">
        <div class="tab">
            <div class="long-text">
                <label>&nbsp;项目名称&nbsp;:</label>
                <input type="text" id="ProjectName" value="@Model.ProjectName" disabled />
                <i class="pic iconfont" width="20" height="30" style="cursor:pointer; left:596px;">&#xe76a;</i>
                <input type="hidden" id="ProjectId" name="ProjectId" value="@Model.ProjectId" />
            </div>
            <div class="long-text">
                <label for="ChangeNo">&nbsp;变更名称&nbsp;:</label>
                <input type="text" id="ChangeName" name="ChangeName" value="@Model.ChangeName" disabled />
            </div>
            <div class="intro">
                <div><label>&nbsp;变更内容&nbsp;:</label></div>
                <div>
                    <textarea class="sub-description" disabled>@Model.ChangeContent</textarea>
                </div>
            </div>
            <div class="intro">
                <div><label>&nbsp;变更原因&nbsp;:</label></div>
                <div>
                    <textarea class="sub-description" disabled>@Model.ChangeReason</textarea>
                </div>
            </div>
            <div class="long-text">
                <label for="ChangeNo">&nbsp;变更号&nbsp;:</label>
                <input type="text" id="ChangeNo" name="ChangeNo" value="@Model.ChangeNo" disabled />
            </div>
            <div class="long-text">
                <label>&nbsp;项目总金额&nbsp;:</label>
                <input type="text" value="@Model.TotalAmount.ToString("0.######")" disabled />&nbsp;&nbsp;&nbsp;万元
            </div>
            <div class="long-text">
                <label>&nbsp;调增额&nbsp;:</label>
                <input type="text" value="@Model.AddAmount.ToString("0.######")" disabled />&nbsp;&nbsp;&nbsp;万元
            </div>
            <div class="long-text">
                <label>&nbsp;调减额&nbsp;:</label>
                <input type="text" value="@Model.ReduceAmount.ToString("0.######")" disabled />&nbsp;&nbsp;&nbsp;万元
            </div>
            <div class="long-text">
                <label>&nbsp;变更金额&nbsp;:</label>
                <input type="text" value="@Model.ChangeAmount.ToString("0.######") " disabled />&nbsp;&nbsp;&nbsp;万元
            </div>
            <div class="short-text">
                <label>&nbsp;开始时间&nbsp;:</label>
                <input type="text" id="ChangeStartTime" name="ChangeStartTime" onClick="WdatePicker({ el: 'ChangeStartTime' })" value="@(Model.ChangeStartTime == null ? "" : Convert.ToDateTime(Model.ChangeStartTime).ToString("yyyy-MM-dd"))" disabled>
                <i onClick="WdatePicker({ el: 'ChangeStartTime' })" class="pic iconfont" width="20" height="30" style="cursor:pointer">&#xe7e2;</i>
            </div>
            <div class="short-text">
                <label>&nbsp;截止时间&nbsp;:</label>
                <input type="text" id="ChangeEndTime" name="ChangeEndTime" onClick="WdatePicker({ el: 'ChangeEndTime' })" value="@(Model.ChangeEndTime == null ? "" : Convert.ToDateTime(Model.ChangeEndTime).ToString("yyyy-MM-dd"))" disabled>
                <i onClick="WdatePicker({ el: 'ChangeEndTime' })" class="pic iconfont" width="20" height="30" style="cursor:pointer">&#xe7e2;</i>
            </div>
            <div class="upload" style="margin-bottom:0px;">
                <div><label>&nbsp;附件上传&nbsp;:</label></div>
            </div>
            <div style="width:100%;" id="fileListFile">
                <ul class="fileShow" id="fileDetail"></ul>
                <input type="hidden" name="fileDataJsonFile" id="fileDataJsonFile">
            </div>
            <div class="button-group btn-center">

                @if (Model.State == (int)ApprovalState.WaitAppr)
                {
                    <button type="button" class="Audit checkright" data-module="EngineeringChange" data-right="Check">审核</button>
                    <button type="button" class="Reject checkright" data-module="EngineeringChange" data-right="UnCheck">驳回</button>
                }
                else if (Model.State == (int)ApprovalState.ApprFailure)
                {
                    @*<button type = "button" class="Discard checkright" data-module="EngineeringChange" data-right="Invalid">废弃</button>*@
                }
                <button type="button" class="exchange">沟通</button>
            </div>
        </div>
    </div>
    <script>
        layui.use(['layer', 'element', 'laypage'], function () {
                    var layer = layui.layer, form = layui.form, element = layui.element, $ = layui.jquery, laypage = layui.laypage;
            //获取附件
            $.post("/Files/GetFileList", { tableName: 'Epm_Change', id: '@Model.Id' }, function (data) {
                        if (data.Flag) {
                            if (data.Data.length > 0) {
                                data.Data.forEach(function (item, index, arr) {
                                    if (item.ImageType == null) {
                                        var odiv = '<li id="' + item.GuidId + '">';
                                        odiv += '<div class="downloadFile"><img src="' + getFileImg(item.Name) + '" style="width: 20px;height: 20px;cursor: pointer;" class="imgShow"/><a href="javascript:;" target="_blank">' + item.Name + '</a></div>';
                                        odiv += '<div>' + item.Size + '</div>';
                                        odiv += '<span style="margin-left:20px;">' + item.CreateUserName + '</span>';
                                        odiv += '<span style="margin-left:20px;">' + new Date(formatDateByJson(item.CreateTime)).Format("yyyy-MM-dd") + '</span>';
                                        odiv += '<input type="hidden" class="hiddenArea" data-group="' + item.Group + '" data-url="' + item.Url + '" data-filename="' + item.Name + '">';
                                        odiv += '</li>';
                                        $('#fileListFile .fileShow').append(odiv);
                                    }
                                });
                            }
                        } else {
                            parent.layer.alert(data.Message, { icon: 2 });
                        }
                    });
            //下载附件
            $("body").on("click", ".downloadFile", function () {
                        var group = $(this).parent().find(".hiddenArea").data("group");
                        var path = $(this).parent().find(".hiddenArea").data("url");
                        var fileName = $(this).parent().find(".hiddenArea").data("filename");
                        window.location.href = "/Download/DownLoadHB?group=" + group + "&path=" + path + "&fileName=" + fileName;
                    });
            //废弃
            $(".Discard").click(function () {

                        var id = '@Model.Id';
                        var state = "Discarded";
                        if (id != "") {
                            parent.layer.confirm("确认要废弃所选择的项？", { icon: 3 }, function () {
                        $.post("UpdateState", { id: id, state: state }, function (data) {
                                    if (data.Flag) {
                                        parent.layer.msg("废弃成功", { time: 2000, icon: 1 });
                                        window.location.href = "/Change/Index";
                                    } else {
                                        parent.layer.alert(data.Message, { icon: 2 });
                                    }
                                }, "json");
                            }, function () {
                                return;
                            })
                }
                    });

            //驳回
            $(".Reject").click(function () {
                var id = '@Model.Id';
                var state = "ApprFailure";
                parent.layer.prompt({
                    formType: 2,
                    title: '请输入驳回理由',
                    yes: function (index, layero) {
                        // 获取文本框输入的值
                        var value = layero.find(".layui-layer-input").val();
                        if (value) {
                            $.post("UpdateState", { id: id, reason: value, state: state }, function (data) {
                                if (data.Flag) {
                                    parent.layer.msg("驳回成功", { time: 2000, icon: 1 });
                                    window.location.href = "/Change/Index";
                                } else {
                                    parent.layer.alert(data.Message, { icon: 2 });
                                }
                            }, "json");
                        } else {
                            parent.layer.alert("请输入驳回理由！", { icon: 2 });
                        }
                    }
                });
            });
            //审核
            $(".Audit").click(function () {
                        var id = '@Model.Id';
                        var state = "ApprSuccess";
                        parent.layer.confirm("确认审核通过？", { icon: 3 }, function () {
                    $.post("UpdateState", { id: id, state: state }, function (data) {
                                if (data.Flag) {
                                    parent.layer.msg("审核成功", { time: 2000, icon: 1 });
                                    window.location.href = "/Change/Index";
                                } else {
                                    parent.layer.alert(data.Message, { icon: 2 });
                                }
                            }, "json");
                        }, function () {
                            return;
                        })
            });
            //沟通
            $('.exchange').on('click', function () {
                        var projectId = $("#ProjectId").val();
                        window.location.href = "/Question/Add?businType=Change&projectId=" + projectId + "&BusinessId=@Model.Id";
                    });
                });
    </script>
}
</body>